
package com.kovalko.webdriver;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import com.kovalko.utils.Log4Test;
import com.kovalko.utils.PropertyLoader;

import java.io.File;

/**
 * Created with IntelliJ IDEA.
 * User: admin
 * Date: 12.06.14
 * Time: 18:23
 * To change this template use File | Settings | File Templates.
 */
public class WebDriverFactory {
    public static final String CHROME = "chrome";
    public static final String FIREFOX = "firefox";
    public static WebDriver initDriver(String browserName)
    {
        WebDriver driver = null;
        switch (browserName) {
            case FIREFOX:
                driver = new FirefoxDriver();
                break;
            case CHROME:
                File file = new File(PropertyLoader.loadProperty("selenium.chrome.driver.path"));
                System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
                driver = new ChromeDriver();
                break;
            default:
                Assert.fail(Log4Test.error("WebDriver not defined"));
                break;
        }
        return new WebDriverWrapper(driver);
    }
}